<?php
namespace app\common\model;
use think\Model;

class SettlementOrder extends Model
{
    protected $connection = 'db_config_aiqi';


    public function updateSettleOrder(array $data)
    {
        // 查找是否已存在相同日期的记录
        $exists = $this->where([
            'order_no'=>$data['order_no'],
            'cid' => $data['cid'],
            'gid' => $data['gid'],
            'cp_id' => $data['cp_id']
        ])->find();

        if ($exists) {
            // 更新现有记录
            return $this->where('id', $exists['id'])->update($data);
        } else {
            // 插入新记录
            return $this->insert($data);
        }
    }


}